package com.wedo.mall.activity.goods;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.e.library.activity.EActivity;
import com.e.library.http.EApi;
import com.e.library.http.EClient;
import com.e.library.http.EObserver;
import com.e.library.http.EResponse;
import com.wedo.mall.R;
import com.wedo.mall.adapter.GoodsCategoryAdapter;
import com.wedo.mall.entity.GoodsCategory;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by lxy on 2017/6/19.
 */

public class GoodsCategoryActivity extends EActivity {

    @BindView(R.id.rv_category) RecyclerView rv_category;
    private GoodsCategoryAdapter mGoodsCategoryAdapter;

    @Override
    protected int layout() {
        return R.layout.activity_goods_category;
    }

    @Override
    protected void onActivityCreated(Bundle state) {
        rv_category.setHasFixedSize(true);
        rv_category.setNestedScrollingEnabled(false);
        rv_category.setLayoutManager(new GridLayoutManager(this,4));
        mGoodsCategoryAdapter = new GoodsCategoryAdapter(this,new ArrayList<GoodsCategory>());
        mGoodsCategoryAdapter.listener(this);
        rv_category.setAdapter(mGoodsCategoryAdapter);
        categories();
    }

    private void categories(){

        loading();
        EClient.with().post(EApi.INDEX_GOODS_CATEGORY, new EObserver() {
            @Override
            public void successful(EResponse response) {
                dismiss();
                List<GoodsCategory> list = response.list(GoodsCategory.class);
                mGoodsCategoryAdapter.refresh(list);
            }

            @Override
            public void failure(String msg) {
                dismiss(msg);
            }
        });
    }
}
